package download

import (
	"gitee.com/swsk33/landsat-fetch/api"
	"gitee.com/swsk33/landsat-fetch/global"
	"gitee.com/swsk33/sclog"
	"github.com/spf13/cobra"
)

// 删除下载任务的子命令
var deleteCmd = &cobra.Command{
	Use:   "delete",
	Short: "删除下载任务列表",
	Long:  "删除某个下载任务列表",
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			sclog.ErrorLine("请指定要删除的下载任务列表名称为第一个参数！")
			return
		}
		// 登录
		e := api.Login(global.TotalConfig.Auth.Username, global.TotalConfig.Auth.Token)
		if e != nil {
			sclog.ErrorLine(e.Error())
			return
		}
		// 删除
		e = api.DeleteDownloadList(args[0])
		if e != nil {
			sclog.ErrorLine(e.Error())
			return
		}
		sclog.Info("已删除下载任务列表：%s\n", args[0])
	},
}

func init() {
	RootDownloadCmd.AddCommand(deleteCmd)
}